<template>
  <HomePanel ref="target" title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
    <template #right>
      <XtxMore />
    </template>
    <template #default>
      <HomeGoodList :goodList="prdList" />
    </template>
  </HomePanel>
</template>

<script>
import HomePanel from './home-panel.vue'
import HomeGoodList from './home-good-list.vue'
import { ref } from 'vue'
import { findNew } from '@/api/home'
// 导入全局公用的钩子函数
import { useObserver } from '@/hooks'

// 函数式编程
const useNew = () => {
  // 商品列表
  const prdList = ref([])
  // 获取商品列表数据
  const getPrdList = async () => {
    const { result } = await findNew()
    prdList.value = result
  }

  return { prdList, getPrdList }
}
export default {
  name: 'HomeNew',
  components: {
    HomePanel,
    HomeGoodList
  },
  setup () {
    // 商品列表
    const { prdList, getPrdList } = useNew()
    // 调用监控函数
    const { target } = useObserver(getPrdList)
    return { prdList, target }
  }
}
</script>

<style scoped lang='less'>
</style>
